{% extends "templates/base.phtml" %}
{%block content%}
{% if wxc is defined %}
<div class="page-content-wrap">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default tabs">
                {%include 'include/wx_tabs' with ['action':action]%}
                <div class="panel-body tab-content">
                    <div class="tab-pane active">
                        <div class="col-md-12">
                            <h3>微信自定义菜单配置</h3>
                            <a type="button" class="btn btn-success" data-reveal-id="myModal" order="0">+&nbsp;添加主菜单</a>
                            <span>*最多添加3个主菜单，5个子菜单</span>

                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                    <tr>
<!--                                        <th>显示顺序</th>-->
                                        <th class="no-center">主菜单名称</th>
                                        <th>关联关键词</th>
                                        <th>外链URL</th>
                                        <th width="20%">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {%for menu in menu%}
                                    <tr>
<!--                                        <td>-->
<!--                                            <p>{{menu['sort']}}</p>-->
<!--                                        </td>-->
                                        <td class="no-center">
                                            <p>{{menu['title']}}</p>
                                        </td>
                                        <td>
                                            <p>{{menu['keyword']}}</p>
                                        </td>
                                        <td>
                                            <p>{{menu['url']}}</p>
                                        </td>
                                        <td>
                                            <a class="btn btn-primary" type="button" data-reveal-id="myModal"
                                               order="{{menu['id']}}">修改</a>
                                            <button class="btn btn-danger" onclick="deleteConfirm({{ menu['id'] }});">
                                                删除
                                            </button>
                                        </td>
                                    </tr>
                                    {%for menu in menu['sub'] %}
                                    <tr>
<!--                                        <td>-->
<!--                                            <p>{{menu['sort']}}</p>-->
<!--                                        </td>-->
                                        <td class="no-center">
                                            <p>|------{{menu['title']}}</p>
                                        </td>
                                        <td>
                                            <p>{{menu['keyword']}}</p>
                                        </td>
                                        <td>
                                            <p>{{menu['url']}}</p>
                                        </td>
                                        <td>
                                            <a class="btn btn-primary" type="button" data-reveal-id="myModal"
                                               order="{{menu['id']}}">修改</a>
                                            <button class="btn btn-danger"  onclick="deleteConfirm({{ menu['id'] }});">删除</button>
                                        </td>
                                    </tr>


                                    {%endfor%}
                                    {%endfor%}

                                    </tbody>
                                </table>
                            </div>
                                <div class="form-group">
                                    <div class="col-md-6 col-sm-4 col-xs-4">
                                        <button class="col-md-3 col-md-offset-9 btn btn-primary" onclick="createmenuConfirm()">生成自定义菜单</button>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{%endif%}
{%endblock%}
{%block div%}
<div id="myModal" class="reveal-modal row">
    <iframe class="class-add" src="" frameborder="0"></iframe>
    <a class="close-reveal-modal">&#215;</a>
</div>
{%endblock%}
{%block end%}
<style type="text/css">
    .user-info-penal p{
        padding-top: 0.6em;
    }
    table th,table td{
        text-align: center;
    }
    .no-center{
        text-align: left;
    }
    iframe.class-add{
        width: 100%;
        height: 100%;
    }
    /*弹出层样式*/
    .reveal-modal-bg {
        position: fixed;
        height: 100%;
        width: 100%;
        background-color: #000;
        z-index: 100;
        display: none;
        top: 0;
        left: 0;
    }
    .reveal-modal {
        visibility: hidden;
        top: 100px;
        left: 50%;
        margin-left: -420px;
        width: 900px;
        height: 400px;
        max-height: 500px;
        background: rgba(238, 238, 238, 0.95);
        position: absolute;
        z-index: 101;
        padding:75px 20px 10px;

        -moz-border-radius: 5px;
        -webkit-border-radius: 5px;
        border-radius: 5px;
        -moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
        -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
        -box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
    }
    .reveal-modal .close-reveal-modal {
        font-size: 22px;
        line-height: .5;
        position: absolute;
        top: 8px;
        right: 11px;
        color: #aaa;
        text-shadow: 0 -1px 1px rbga(0, 0, 0, 0.6);
        font-weight: bold;
        cursor: pointer;
    }
    /*弹出层样式 end*/
</style>
<script type="application/javascript">
    $(document).ready(function () {
        $("a[order]").click(function () {
            var order = $(this).attr("order");
            if (order != 0) {
                $("iframe").attr("src", "/admin/appwx/addmenu/" + order);
            } else {
                $("iframe").attr("src", "/admin/appwx/addmenu/");
            }
        });
    });
</script>
<script type="text/javascript">
    function deleteConfirm(delete_id) {
        noty({
            text: '确定要删除此菜单么?',
            layout: 'topRight',
            buttons: [
                {
                    addClass: 'btn btn-success btn-clean', text: '确定', onClick: function ($noty) {
                    $noty.close();
                    $.post('/admin/appwx/delmenu/' + delete_id, {}, function (result) {
                        noty({text: '删除成功', layout: 'topRight', type: 'success'}
                        );
                        location.reload();
                    });
                }
                },
                {
                    addClass: 'btn btn-danger btn-clean', text: '取消', onClick: function ($noty) {
                    $noty.close();
                }
                }
            ]
        })
    }
</script>
<script type="text/javascript">
    function createmenuConfirm() {
        noty({
            text: '确定要生成此菜单么?',
            layout: 'topRight',
            buttons: [
                {
                    addClass: 'btn btn-success btn-clean', text: '确定', onClick: function ($noty) {
                    $noty.close();
                    $.post('/admin/appwx/createmenu/', {}, function (result) {
                        noty({text: '自定义菜单成功', layout: 'topRight', type: 'success'}
                        );
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    });
                }
                },
                {
                    addClass: 'btn btn-danger btn-clean', text: '取消', onClick: function ($noty) {
                    $noty.close();
                }
                }
            ]
        })
    }
</script>
{%endblock%}